home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / creastdi.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  3KB  |  111 lines

  1. /***********************************************************************
  2. *
  3. *       Exec Support Functions -- Standard IO Requests
  4. *
  5. ***********************************************************************/
  6.  
  7. #include "exec/types.h"
  8. #include "exec/nodes.h"
  9. #include "exec/lists.h"
  10. #include "exec/memory.h"
  11. #include "exec/interrupts.h"
  12. #include "exec/ports.h"
  13. #include "exec/libraries.h"
  14. #include "exec/io.h"
  15. #include "exec/tasks.h"
  16. #include "exec/execbase.h"
  17.  
  18. extern APTR AllocMem();
  19.  
  20.  
  21. /****** exec_support/CreateStdIO **************************************
  22. *
  23. *   NAME        
  24. *       CreateStdIO() -- create a standard IO request
  25. *
  26. *   SYNOPSIS
  27. *       ioStdReq = CreateStdIO(ioReplyPort);   
  28. *
  29. *   FUNCTION
  30. *       Allocates memory for and initializes a new IO request block.
  31. *
  32. *   INPUTS
  33. *       ioReplyPort - a pointer to an already initialized
  34. *               message port to be used for this IO request's
  35. *               reply port.
  36. *
  37. *   RESULT
  38. *       Returns a pointer to the new block.  Pointer is of the type:
  39. *       struct IOStdReq
  40. *       0 indicates inability to allocate enough memory for either
  41. *       the request block.
  42. *
  43. *   EXAMPLE
  44. *       struct IOStdReq *myBlock;
  45. *       if( (myBlock = CreateStdIO(myPort)) == NULL)
  46. *               printf("Insufficient memory or not enough signals!");
  47. *
  48. *   SEE ALSO
  49. *       DeleteStdIO
  50. *
  51. ***********************************************************************/
  52.  
  53. struct IOStdReq *CreateStdIO(ioReplyPort)
  54.     struct MsgPort *ioReplyPort;
  55. {
  56.     struct IOStdReq *ioStdReq;
  57.  
  58.     if (ioReplyPort == 0)
  59.         return ((struct IOStdReq   *) 0);
  60.  
  61.     ioStdReq = AllocMem (sizeof (*ioStdReq), MEMF_CLEAR | MEMF_PUBLIC);
  62.  
  63.     if (ioStdReq == 0)
  64.         return ((struct IOStdReq   *) 0);
  65.  
  66.     ioStdReq -> io_Message.mn_Node.ln_Type = NT_MESSAGE;
  67.     ioStdReq -> io_Message.mn_Node.ln_Pri = 0;
  68.  
  69.     ioStdReq -> io_Message.mn_ReplyPort = ioReplyPort;
  70.  
  71.     return (ioStdReq);
  72. }
  73.  
  74.  
  75. /****** exec_support/DeleteStdIO ***************************************
  76. *
  77. *   NAME
  78. *       DeleteStdIO(ioStdReq) - return memory allocated for IO request
  79. *
  80. *   SYNOPSIS
  81. *       DeleteStdIO(ioStdReq);
  82. *
  83. *   FUNCTION
  84. *       See summary line at NAME.  Also frees the signal bit which
  85. *       had been allocated by the call to CreateStdIO.
  86. *
  87. *   INPUTS
  88. *       A pointer to the IOStdReq block whose resources are to be freed.
  89. *
  90. *   RESULT
  91. *       Frees the memory.  Returns (no error conditions shown)
  92. *
  93. *   EXAMPLE
  94. *       struct IOStdReq *myBlock;
  95. *       DeleteStdIO(myBlock);
  96. *
  97. *   SEE ALSO
  98. *       CreateStdIO
  99. *
  100. **************************************************************************/
  101.  
  102. DeleteStdIO(ioStdReq)
  103.     struct IOStdReq *ioStdReq;
  104. {
  105.     ioStdReq -> io_Message.mn_Node.ln_Type = 0xff;
  106.     ioStdReq -> io_Device = (struct Device *) -1;
  107.     ioStdReq -> io_Unit = (struct Unit *) -1;
  108.  
  109.     FreeMem (ioStdReq, sizeof (*ioStdReq));
  110. }
  111.